package com.armrest.screen;


import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

public class OverlayDecoration extends RecyclerView.ItemDecoration {
    private Paint paint;
    private int overlayColor;

    public OverlayDecoration(int overlayColor) {
        this.overlayColor = overlayColor;
        paint = new Paint();
        paint.setColor(overlayColor);
        paint.setStyle(Paint.Style.FILL);
    }

    @Override
    public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
        super.onDraw(c, parent, state);
        for (int i = 0; i < parent.getChildCount(); i++) {
            View child = parent.getChildAt(i);
            Rect bounds = new Rect();
            paint.setAlpha(100); // 设置叠加层的透明度
            c.drawRect(child.getLeft(), child.getTop(), child.getRight(), child.getBottom(), paint);
        }
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        // 设置ItemDecoration的间隔，如果不需要间隔可以不重写此方法
    }
}
